package org.dromara.company.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.admin.domain.model.EmployeeRegisterBody;
import org.dromara.admin.domain.model.UserRegisterBody;
import org.dromara.admin.service.IRegisterService;
import org.dromara.common.core.domain.R;
import org.dromara.common.encrypt.annotation.ApiEncrypt;
import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公司注册
 *
 * @author Lion Li
 */
@Slf4j
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/company")
public class CompanyRegisterController {

    private final IRegisterService registerService;

    /**
     * 注册公司
     */
    @PostMapping("/registerCompany")
    public R<Void> register(@RequestBody UserRegisterBody user) {
        registerService.registerCompany(user);
        return R.ok();
    }

    /**
     * 公司注册员工账号
     */
    @PostMapping("/registerEmployee")
    public R<Void> registerEmployee(@RequestBody EmployeeRegisterBody user) {
        Long userId = LoginHelper.getUserId();
        if (userId == null) {
            return R.fail("请先登录！");
        }
        user.setLoginUserId(userId);
        registerService.registerEmployee(user);
        return R.ok();
    }
}
